/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IPhotoDao;
import com.qiyou.dao.impl.PhotoDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.Photo;
import com.qiyou.util.DBUtil;

/**
 * 照片数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class PhotoDaoProxy implements IPhotoDao {
    private Connection conn = null;
    private IPhotoDao dao = null;

    public PhotoDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new PhotoDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Photo photo) throws SQLException {
        if (null != photo) {
            try {
                return dao.doCreate(photo);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doUpdate(Photo photo) throws SQLException {
        if (null != photo) {
            try {
                return dao.doUpdate(photo);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(long photoID) throws SQLException {
        if (photoID > 0) {
            try {
                return dao.doDelete(photoID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public Photo getPhoto(long photoID) throws SQLException {
        if (photoID > 0) {
            try {
                return dao.getPhoto(photoID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<Photo> getPhotos(long albumID) throws SQLException {
        if (albumID > 0) {
            try {
                return dao.getPhotos(albumID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<Photo> getPhotos(Object... params) throws SQLException {
        if (null != params) {
            try {
                return dao.getPhotos(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
